<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <style>
        .on{background:#f00;}
    </style>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>

<div class="container strategies">
    <h5 class="title" render-html="title"></h5>
    <small><span>1523</span>人阅读过此攻略</small>
    <div class="focus">
        <i class="fa fa-heart"><span> 234</span> 收藏</i>
        <i class="fa fa-thumbs-up"   id="likeBtn" data-key="on"><span id="likeCount"></span> 点赞</i>
        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">
        <div class="container hot" >
            <h6>大家都在看</h6>
            <div render-loop="list.travel">
                <a href="travelContent.html?id=" render-fun="setHref" render-key="list.travel.id" >
                    <button class="btn" render-html="list.travel.title"></button>
                </a>
            </div>
        </div>
        <div class="catalogs">
            <div render-loop="list">
                <div class="container detail" >
                    <h6 render-fun="setName" render-key="list.name"></h6>
                    <div render-loop="list.details">
                        <a href="/strategyDetails.html?id=" render-fun="setHref" render-key="list.details.id">
                            <button class="btn" render-html="list.details.title"></button>
                        </a>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <div class="tab-pane fade " id="pills-comment">

        <div class="container tag">
            <h6>骡友标签</h6>
            <div render-loop="listtag">
                <span render-html="listtag.name"></span>

            </div>
        </div>
        <hr>

        <div id="comment">
            <div render-loop="list" >
                <div class="container row comment">
                    <div class="col-2 comment-head">
                        <a href="/userProfiles.html"  >
                            <img class="rounded-circle"
                                 render-src="list.user.headImgUrl">
                        </a>
                    </div>
                    <div class="col comment-right">
                        <p class="authorName"><span render-html="list.user.nickName"></span></p>
                        <span class="comment-star" ><i
                                class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i
                                class="fa fa-star"></i><i class="fa fa-star-o"></i></span>
                        <span class="comment-date" render-html="commendTime"></span>
                        <div class="comment-content">
                            <a href="/mine/strategySunComment.html?id=" render-fun="setHref" render-key="list.id" >
                                <p render-html="list.content"></p>
                            </a>
                        </div>


                        <ul class="comment-img" render-loop="list.imgArray">
                            <li>
                                <img  render-src="list.imgArray.self">
                            </li>
                        </ul>


                        <div class="d-flex icon">
                            <a href="/mine/strategySunComment.html?id=" render-fun="setHref" render-key="list.id" >
                                <i class="fa  fa-commenting-o " style="margin-right: 10px"> 评论 </i>

                            </a>
                            <button class="fa fa-thumbs-o-up likeComment"  data-key="on" render-key="list.id" render-fun="serClass" > </button>
                        </div>


                    </div>
                </div>

                </div>
            </div>
        </div>

    </div>
</div>

<div class="operation">
    <button class="btn">加入旅行单</button>
    <button class="btn" id="commentBtn">点评</button>
</div>


<script>
    $(function () {
        //渲染大攻略的数据
        var params = getParams();
        var userStr = sessionStorage.getItem("user");
        var user = JSON.parse(userStr);
        if (user){
          var  userId=user.id;
        }
        if(params.id){
            $.get("/strategies/"+params.id,function (data) {
                $(".strategies").renderValues(data);
            })
            //大家都在看的数据渲染

            //某个大攻略下所有的目录分类
            $.get("/strategies/"+params.id+"/catalogs",function (data) {
                console.log(data);
                var count = 1;
                $(".catalogs").renderValues({list:data},{
                    setName:function (ele, value) {
                        $(ele).html("0"+count+"/"+value)
                        count++;
                    },
                    setHref:function (ele, value) {
                        $(ele).attr("href",$(ele).attr("href")+value)
                    }
                })
            })

            //点评内容的渲染--------------------------------------------------
            $.get("/strategies/"+params.id+"/comments",function (data) {
                /*console.log(data);*/
                $("#comment").renderValues({list:data},{
                    setHref:function (ele, value) {
                        $(ele).attr("href",$(ele).attr("href")+value);
                    } ,
                    serClass:function (ele, value) {
                    $.get("/strategyComments/"+value+"/isExist",{userId:userId},function (data) {
                        if (data.success){
                            $(ele).attr("data-key","")
                            $(ele).addClass("on");
                            console.log(ele);
                        }
                            $(ele).attr("data-id",value)
                    })
                }
                })
            },"json")

            //点评标签的渲染---------------------------------------------------
            $.get("/strategies/"+params.id+"/tags",{pageSize:0},function (data) {
                console.log(data.list);
                $(".tag").renderValues({listtag:data.list})
            })

            //增加点评点击事件
            $("#commentBtn").click(function () {
                //直接跳转点评页面
                location.href="/mine/addComment.html?id="+params.id;
            })


    }

        //大家都在看
        $.get("/strategytravel/"+params.id+"/travel",function (data) {
            console.log(1);
            console.log({list:data});
            //渲染
            $(".hot").renderValues({list:data},{
                setHref:function (ele,value) {
                    $(ele).attr("href",$(ele).attr("href")+value)
                }
            })
        })

        //看看有多少人点了攻略赞
        $.get("/strategies/"+params.id+"/likeCount",{userId:userId},function (data) {
            if (data.success){
                $("#likeBtn").attr("data-key","")
                $("#likeBtn").addClass("on");
            }
            $("#likeCount").html(data.obj)
        })
        //若已经点赞

        /*建立一个函数攻略*/
        $("#likeBtn").click(function () {

                /*获取到id执行点击事件*/
                if (user){
                    if ($(this).attr("data-key")=="on") {
                        $(this).addClass("on");
                        var num = Number($("#likeCount").html()) + 1;

                        $.ajax({
                            type:"post",
                            url:"/strategies/like/saveLike",
                            data:{userId:user.id,strategy:params.id},
                            success:function(data) {
                                if (data.success) {
                                    $(document).dialog({
                                        type: 'notice',
                                        infoText: '点赞成功',
                                        autoClose: 2500,
                                        position: 'bottom'  // center: 居中; bottom: 底部
                                    })
                                }
                            }
                        })
                        /*给变量赋值当.btn点击执行b标签内容=+1*/
                        $("#likeCount").html(num);
                        $(this).attr("data-key", "")
                    } else {
                        $(this).removeClass("on");
                        num = Number($("#likeCount").html()) - 1;
                        $.ajax({
                            type:"delete",
                            url:"/strategies/like/deleteLike",
                            data:{userId:user.id,strategyId:params.id},
                            success:function(data) {
                                if (data.success) {
                                    $(document).dialog({
                                        type : 'notice',
                                        infoText: '取消点赞成功',
                                        autoClose: 2500,
                                        position: 'bottom'  // center: 居中; bottom: 底部
                                    })
                                }
                            }
                        })
                        $("#likeCount").html(num);
                        $(this).attr("data-key", "on");
                    }
                }
                //没登陆不能点赞
                else {
                    alert("请先登陆")
                    // window.location.href="login.html"
                }
            }
        )
        /*建立一个函数攻略评论点赞*/
        $("#comment").on("click",".likeComment",function () {
            var id1 = $(this).data("id");
            console.log(1);
            /*获取到id执行点击事件*/
            if (user){
                if ($(this).attr("data-key")=="on") {
                    $(this).addClass("on");
                    console.log($(this));
                    $.ajax({
                        type:"post",
                        url:"/strategyComments/like/saveLike",
                        data:{userId:user.id,strategyCommentId:id1},
                        success:function(data) {
                            if (data.success) {
                                $(document).dialog({
                                    type: 'notice',
                                    infoText: '点赞成功',
                                    autoClose: 2500,
                                    position: 'bottom'  // center: 居中; bottom: 底部
                                })
                            }
                        }
                    })
                    /*给变量赋值当.btn点击执行b标签内容=+1*/
                    $(this).attr("data-key", "")
                } else {
                    $(this).removeClass("on");
                    console.log($(this));
                    $.ajax({
                        type:"delete",
                        url:"/strategyComments/like/deleteLike",
                        data:{userId:user.id,strategyCommentId:id1},
                        success:function(data) {
                            if (data.success) {
                                $(document).dialog({
                                    type : 'notice',
                                    infoText: '取消点赞成功',
                                    autoClose: 2500,
                                    position: 'bottom'  // center: 居中; bottom: 底部
                                })
                            }
                        }
                    })
                    $(this).attr("data-key", "on");
                }
            }
            //没登陆不能点赞
            else {
                alert("请先登陆")
                // window.location.href="login.html"
            }
        })



    })


</script>

</body>
</html>